package com.example.tijianserver.service;


import com.example.tijianserver.mapper.CidetailedreportMapper;
import com.example.tijianserver.mapper.CireportMapper;
import com.example.tijianserver.mapper.OverallresultMapper;
import com.example.tijianserver.pojo.Cidetailedreport;
import com.example.tijianserver.pojo.Cireport;
import com.example.tijianserver.pojo.Overallresult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

@Service
public class OverallResultServiceImpl implements OverallResultService {
	@Autowired
	OverallresultMapper overallresultMapper;
	@Autowired
	CireportMapper cireportMapper;
	@Autowired
	CidetailedreportMapper cidetailedreportMapper;

	@Override
	public List<Overallresult> getOverallResultById(Overallresult overallResult){

		List<Overallresult> OverallResultList =overallresultMapper.selectByOrderId(overallResult.getOrderId());

		return OverallResultList;
	}

	@Override
	public List<Cireport> getReportByOrderId(Cireport ciReport) {
		List<Cireport> ReportList =cireportMapper.selectByOrderId(ciReport.getOrderId());
		return ReportList;
	}

	@Override
	public List<Cireport> getReportDetailByCiId(Cireport ciReport) {
		// 根据 orderId 获取报告列表
		System.out.println(ciReport.getOrderId());
		List<Cireport> reportDetailList = cidetailedreportMapper.selectByOrderId(ciReport.getOrderId());
		System.out.println(reportDetailList.toString());
		// 创建一个新的列表来存储合并后的结果
		List<Cireport> combinedReportList = new ArrayList<>();

		Integer orderId=ciReport.getOrderId();
		// 遍历每个报告
		for (Cireport report : reportDetailList) {

			System.out.println(report.toString());
			Integer ciId = report.getCiId();


			// 根据 ciId 获取详细信息
			List<Cidetailedreport> detail = cidetailedreportMapper.getReportDetailByciId(ciId,orderId);

			// 将去重后的详细信息添加到报告中
			report.setDetail(detail);

			// 将合并后的报告添加到结果列表中
			combinedReportList.add(report);
		}

		return combinedReportList;
	}



}
